package ACWing.TheNnderlyingAlgorithm.区间合并;
//803.区间合并

import java.util.*;

/**
 * @author :chenjie
 * @date :Created 2022/11/26 20:38
 */
public class IntervalMerging {
    static class PII{
        int l,r;

        public PII(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public String toString() {
            return "PII{" +
                    "l=" + l +
                    ", r=" + r +
                    '}';
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        PII[] list=new PII[n];
        for (int i = 0; i < n; i++) {
            list[i]=new PII(sc.nextInt(),sc.nextInt());
        }
        Arrays.sort(list,(O1,O2)->O1.l-O2.l);
        int sum=0;
        for (int i = 0; i < list.length; i++) {
            int r=list[i].r;
            int j=i;
            while (true){
                j++;
                if(j>list.length-1){//到末尾了
                    sum++;
                    System.out.println(sum);
                    return;
                }
                if(r>=list[j].l){
                    r=Math.max(list[j].r,r);
                }else {
                    sum++;
                    break;
                }
            }
            i=j-1;
        }



    }

}
